package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbBusiness;
import com.ruoyi.business.service.ITbBusinessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
//import io.swagger.v3.oas.annotations.Operation;

/**
 * 商机管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/business/business")
public class TbBusinessController extends BaseController
{
    @Autowired
    private ITbBusinessService tbBusinessService;

    /**
     * 查询商机管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:business:list')")
    @GetMapping("/list")
    @ApiOperation(value = "商机管理列表")
    public TableDataInfo list(TbBusiness tbBusiness)
    {
        startPage();
        List<TbBusiness> list = tbBusinessService.selectTbBusinessList(tbBusiness);
        return getDataTable(list);
    }

    /**
     * 导出商机管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:business:export')")
    @Log(title = "商机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商机管理列表")
    public void export(HttpServletResponse response, TbBusiness tbBusiness)
    {
        List<TbBusiness> list = tbBusinessService.selectTbBusinessList(tbBusiness);
        ExcelUtil<TbBusiness> util = new ExcelUtil<TbBusiness>(TbBusiness.class);
        util.exportExcel(response, list, "商机管理数据");
    }

    /**
     * 获取商机管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:business:query')")
    @GetMapping(value = "/{customerId}")
    @ApiOperation(value = "获取商机管理详细信息")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(tbBusinessService.selectTbBusinessByCustomerId(customerId));
    }

    /**
     * 新增商机管理
     */
    @PreAuthorize("@ss.hasPermi('business:business:add')")
    @Log(title = "商机管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商机管理")
    public AjaxResult add(@RequestBody TbBusiness tbBusiness)
    {
        return toAjax(tbBusinessService.insertTbBusiness(tbBusiness));
    }

    /**
     * 修改商机管理
     */
    @PreAuthorize("@ss.hasPermi('business:business:edit')")
    @Log(title = "商机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商机管理")
    public AjaxResult edit(@RequestBody TbBusiness tbBusiness)
    {
        return toAjax(tbBusinessService.updateTbBusiness(tbBusiness));
    }

    /**
     * 删除商机管理
     */
    @PreAuthorize("@ss.hasPermi('business:business:remove')")
    @Log(title = "商机管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    @ApiOperation(value = "删除商机管理")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(tbBusinessService.deleteTbBusinessByCustomerIds(customerIds));
    }
}
